<?php

Raise::load('core.RaiseHtml');

/**
 * TestCoreRaiseHtml class
 * Testing unit of 'phpraise/core/RaiseHtml.php'
 *
 * @author Sam-Mauris Yong <hellclanner at live dot com>
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
 * @package Raise.UnitTest.Test
 */
class TestCoreRaiseHtml extends RaiseTest {
    public static function testClasses(){
        self::assertClassExists('RaiseHtml');
        self::assertClassMethod('RaiseHtml', array(
            'breakLine',
            'css',
            'decode',
            'div',
            'encode',
            'hyperlink',
            'image',
            'isHTMLSelected',
            'isXHTMLSelected',
            'preformat',
            'script',
            'scriptFile',
            'span',
            'tag',
            'title'
        ));
        self::assertClassExtends('RaiseHtml', 'RaiseStaticClass');
        self::assertClassExists('RaiseHtmlDocType');
        self::assertClassExtends('RaiseHtmlDocType', 'RaiseEnum');
        self::assertClassExists('RaiseHtmlTag');
        self::assertClassExtends('RaiseHtmlTag', 'RaiseObject');

        self::assertConstantDefined('RaiseHtmlDocType::HTML4_01_FRAMSET');
        self::assertConstantDefined('RaiseHtmlDocType::HTML4_01_STRICT');
        self::assertConstantDefined('RaiseHtmlDocType::HTML4_01_TRANSITIONAL');
        self::assertConstantDefined('RaiseHtmlDocType::HTML5');
        self::assertConstantDefined('RaiseHtmlDocType::XHTML1_1');
        self::assertConstantDefined('RaiseHtmlDocType::XHTML1_FRAMESET');
        self::assertConstantDefined('RaiseHtmlDocType::XHTML1_STRICT');
        self::assertConstantDefined('RaiseHtmlDocType::XHTML1_TRANSITIONAL');
        self::assertConstantDefined('RaiseHtmlDocType::XHTML_BASIC_1_1');
    }

    public static function testRaiseHtml(){

        self::assert(RaiseHtmlDocType::HTML4_01_FRAMSET);
        self::assert(RaiseHtmlDocType::HTML4_01_STRICT);
        self::assert(RaiseHtmlDocType::HTML4_01_TRANSITIONAL);
        self::assert(RaiseHtmlDocType::HTML5);
        self::assert(RaiseHtmlDocType::XHTML1_1);
        self::assert(RaiseHtmlDocType::XHTML1_FRAMESET);
        self::assert(RaiseHtmlDocType::XHTML1_STRICT);
        self::assert(RaiseHtmlDocType::XHTML1_TRANSITIONAL);
        self::assert(RaiseHtmlDocType::XHTML_BASIC_1_1);

        RaiseHtml::$selectedDocType = RaiseHtmlDocType::XHTML1_TRANSITIONAL;
        self::assertTrue(RaiseHtml::isXHTMLSelected());
        self::assertFalse(RaiseHtml::isHTMLSelected());
        RaiseHtml::$selectedDocType = RaiseHtmlDocType::HTML5;
        self::assertTrue(RaiseHtml::isHTMLSelected());
        self::assertFalse(RaiseHtml::isXHTMLSelected());
    }

    public static function testBreakLineTag(){
        RaiseHtml::$selectedDocType = RaiseHtmlDocType::XHTML1_1;

        $tag = RaiseHtml::breakLine();
        self::assertObjectClass($tag, 'RaiseHtmlTag');
        self::assertStrictEqual($tag->tagName(), 'br');
        self::assertStrictEqual($tag->value(), '');
        self::assertStrictEqual($tag->html(), '<br />');
        self::assertStrictEqual($tag->attributes()->count(),0);
    }

    public static function testStyleTag(){
        RaiseHtml::$selectedDocType = RaiseHtmlDocType::XHTML1_1;

        $style = '#test{text-align:left;}';
        $tag = RaiseHtml::css($style);
        self::assertObjectClass($tag, 'RaiseHtmlTag');
        self::assertStrictEqual($tag->tagName(), 'style');
        self::assertStrictEqual($tag->value(), $style);
        self::assertTrue($tag->attributes()->keyExists('type'));
        self::assertStrictEqual($tag->attributes()->get('type'),'text/css');

    }

    public static function testDivisionTag(){
        RaiseHtml::$selectedDocType = RaiseHtmlDocType::XHTML1_1;

        $tag = RaiseHtml::div('test');
        self::assertObjectClass($tag, 'RaiseHtmlTag');
        self::assertStrictEqual($tag->tagName(), 'div');
        self::assertStrictEqual($tag->value(), 'test');
        self::assertStrictEqual($tag->html(), '<div>test</div>');
        self::assertStrictEqual($tag->attributes()->count(),0);

        $tag = RaiseHtml::div('test', array('class'=>'testDiv'));
        self::assertObjectClass($tag, 'RaiseHtmlTag');
        self::assertStrictEqual($tag->tagName(), 'div');
        self::assertStrictEqual($tag->value(), 'test');
        self::assertTrue($tag->attributes()->keyExists('class'));
        self::assertStrictEqual($tag->attributes()->get('class'), 'testDiv');

    }

    public static function testHyperlinkTag(){
        RaiseHtml::$selectedDocType = RaiseHtmlDocType::XHTML1_1;

        $tag = RaiseHtml::hyperlink('Visit phpRaise!', 'http://code.google.com/p/phpraise');
        self::assertObjectClass($tag, 'RaiseHtmlTag');
        self::assertStrictEqual($tag->tagName(), 'a');
        self::assertStrictEqual($tag->value(), 'Visit phpRaise!');
        self::assertTrue($tag->attributes()->keyExists('href'));
        self::assertStrictEqual($tag->attributes()->get('href'), 'http://code.google.com/p/phpraise');
        self::assertStrictEqual($tag->html(), '<a href="http://code.google.com/p/phpraise">Visit phpRaise!</a>');

        $tag = RaiseHtml::hyperlink('Visit phpRaise today!', 'http://code.google.com/p/phpraise', array('target'=>'_blank'));
        self::assertObjectClass($tag, 'RaiseHtmlTag');
        self::assertStrictEqual($tag->tagName(), 'a');
        self::assertStrictEqual($tag->value(), 'Visit phpRaise today!');
        self::assertObjectClass($tag->attributes(), 'RaiseCollection');
        self::assertTrue($tag->attributes()->keyExists('target'));
        self::assertTrue($tag->attributes()->valueExists('_blank'));
        self::assertStrictEqual($tag->attributes()->get('target'), '_blank');
        self::assertArrayHasKey($tag->attributes()->toArray(), 'target');
        self::assertArrayHasElement($tag->attributes()->toArray(), '_blank');
        self::assertType($tag->attributes()->toArray(), 'array');

    }

    public static function testImageTag(){
        RaiseHtml::$selectedDocType = RaiseHtmlDocType::XHTML1_1;

        $tag = RaiseHtml::image('test.jpg', array('width'=>'100px', 'height'=>'200px'));
        self::assertObjectClass($tag, 'RaiseHtmlTag');
        self::assertStrictEqual($tag->tagName(), 'img');
        self::assertStrictEqual($tag->value(), '');
        self::assertTrue($tag->attributes()->keyExists('src'));
        self::assertTrue($tag->attributes()->keyExists('width'));
        self::assertTrue($tag->attributes()->keyExists('height'));
        self::assertStrictEqual($tag->attributes()->get('src'), 'test.jpg');
        self::assertStrictEqual($tag->attributes()->get('width'), '100px');
        self::assertStrictEqual($tag->attributes()->get('height'), '200px');

    }

    public static function testPreformatTag(){
        RaiseHtml::$selectedDocType = RaiseHtmlDocType::XHTML1_1;

        $tag = RaiseHtml::preformat('echo \'test\';');
        self::assertObjectClass($tag, 'RaiseHtmlTag');
        self::assertStrictEqual($tag->tagName(), 'pre');
        self::assertStrictEqual($tag->value(), 'echo \'test\';');
        self::assertStrictEqual($tag->html(), '<pre>echo \'test\';</pre>');
        self::assertStrictEqual($tag->attributes()->count(),0);

    }

    public static function testScriptTag(){
        RaiseHtml::$selectedDocType = RaiseHtmlDocType::XHTML1_1;

        $tag = RaiseHtml::script('alert(\'test\');');
        self::assertObjectClass($tag, 'RaiseHtmlTag');
        self::assertStrictEqual($tag->tagName(), 'script');
        self::assertStrictEqual($tag->value(), '/* <![CDATA[ */ alert(\'test\'); /* ]]> */');
        self::assertTrue($tag->attributes()->keyExists('type'));
        self::assertStrictEqual($tag->attributes()->get('type'),'text/javascript');

        $tag = RaiseHtml::scriptFile('test/s.js');
        self::assertObjectClass($tag, 'RaiseHtmlTag');
        self::assertStrictEqual($tag->tagName(), 'script');
        self::assertStrictEqual($tag->attributes()->get('src'), 'test/s.js');
        self::assertTrue($tag->attributes()->keyExists('type'));
        self::assertStrictEqual($tag->attributes()->get('type'),'text/javascript');

    }

    public static function testSpanTag(){
        RaiseHtml::$selectedDocType = RaiseHtmlDocType::XHTML1_1;

        $txt = 'The great brown fox jump over the lazy dog and bit a bone off the plate.';
        $tag = RaiseHtml::span($txt, array('style'=>'font-size:30px;'));
        self::assertObjectClass($tag, 'RaiseHtmlTag');
        self::assertStrictEqual($tag->tagName(), 'span');
        self::assertTrue($tag->attributes()->keyExists('style'));
        self::assertStrictEqual($tag->value(), $txt);
        self::assertStrictEqual($tag->attributes()->get('style'), 'font-size:30px;');
    }

    public static function testTitleTag(){
        RaiseHtml::$selectedDocType = RaiseHtmlDocType::XHTML1_1;

        $title = 'phpRaise | the php framework you probably need and want';
        $tag = RaiseHtml::title($title);
        self::assertObjectClass($tag, 'RaiseHtmlTag');
        self::assertStrictEqual($tag->tagName(), 'title');
        self::assertStrictEqual($tag->value(), $title);
        self::assertStrictEqual($tag->attributes()->count(),0);

    }
}

